<template>
  <div class="view-fill">
    <div v-if="!modifyInfo.visible" class="app-container-flex">
      <FullScreen
        v-model="showDialog"
        title="项目需求详情"
        @returnBack="returnBack"
      >
        <template v-slot:full-button>
          <el-button v-if="$permission('biddingProject:update')" @click="update"
            >修改</el-button
          >
        </template>
        <div class="model-panel">
          <div class="model-panel-title">
            <p>{{ $t('basic_information') }}</p>
          </div>
          <div class="model-panel-body">
            <basic-information :info="infoList" />
          </div>
        </div>
        <div class="model-panel">
          <div class="model-panel-title">
            <p>应标供应商</p>
          </div>
          <div class="model-panel-body">
            <div class="flex_full_item">
              <!-- 表格 -->
              <PageTable
                v-model:data="tableInfo.data"
                :pager="false"
                :checkBox="false"
                :tab-index="true"
                :isDynamic="true"
                :field-list="tableInfo.fieldList"
              >
                <template v-slot:col-filePathList="scope">
                  <EleGallery
                    v-if="
                      scope.row.filePathList && scope.row.filePathList.length
                    "
                    :lazy="true"
                    :size="40"
                    :source="scope.row.filePathList"
                    title="投标文档"
                  />
                  <span v-else>-</span>
                </template>
              </PageTable>
            </div>
          </div>
        </div>
      </FullScreen>
    </div>

    <Modify
      v-if="modifyInfo.visible"
      v-model:visible="modifyInfo.visible"
      :orderId="modifyInfo.orderId"
      :title="modifyInfo.title"
      @returnModify="returnModify"
    />
  </div>
</template>

<script setup>
const Modify = defineAsyncComponent(() => import('./modify'))
import { getProjectById, getProjectAll } from '@/api/bidding.js'
import EleGallery from '@/components/UploadImgNew/eleGallery'
const { proxy } = getCurrentInstance()
const props = defineProps(['visible', 'orderId'])
const infoList = ref({
  data: [],
  fieldList: [
    { label: '招标编号', value: 'biddingNumber', type: 'text' },
    { label: '项目名称', value: 'name', type: 'text' },
    { label: '预算金额', value: 'budgetAmount', type: 'text' },
    {
      label: '开标时间',
      value: 'openTime',
      type: 'text',
    },
    { label: '开标地点', value: 'openAddress', type: 'text' },
    { label: '采购人', value: 'purchUser', type: 'text' },
    { label: '采购联系人', value: 'purchContactUser', type: 'text' },
    { label: '采购联系人电话', value: 'purchContactUserTel', type: 'text' },
    { label: '采购代理机构', value: 'purchAgency', type: 'text' },
    { label: '代理机构联系人', value: 'agencyUser', type: 'text' },
    { label: '代理机构联系人电话', value: 'agencyUserTel', type: 'text' },
    { label: '关联招标参数', value: 'biddingParameterName', type: 'text' },
    {
      label: '备注',
      value: 'remark',
      type: 'textarea',
    },
  ],
})
// 过滤相关配置
const filterInfo = ref({
  query: {
    biddingProjectId: props.orderId,
  },
})
const modifyInfo = ref({
  visible: false,
  title: '',
  orderId: '',
})
// 表格相关
const tableInfo = ref({
  api: null,
  data: [],
  fieldList: [
    {
      label: '供应商名称',
      value: 'supplierName',
    },
    {
      label: '供应商联系人',
      value: 'supplierContactUser',
    },
    {
      label: '供应商联系人电话',
      value: 'supplierContactUserTel',
    },
    {
      label: '投标金额',
      value: 'biddingAmount',
    },
    {
      label: '是否中标',
      value: 'isSuccessBiddingValue',
    },
    {
      label: '评标分数',
      value: 'bidEvaluationScore',
    },
    {
      label: '专家意见',
      value: 'expertOpinion',
    },
    {
      label: '投标文档',
      value: 'filePathList',
      type: 'slot',
    },
  ],
})
const showDialog = computed({
  get() {
    return props.visible
  },
  set(val) {
    proxy.$emit('update:visible', val) // 更新父组件visible
  },
})

onMounted(() => {
  if (props.orderId) {
    getMain()
  }
})
function returnModify() {
  getMain()
}
function returnBack() {
  proxy.$emit('returnBack', false)
}

//更新
function update() {
  modifyInfo.value.orderId = infoList.value.data.id
  modifyInfo.value.title = '修改招标项目'
  modifyInfo.value.visible = true
}
function getMain() {
  getProjectById(props.orderId).then((resp) => {
    if (resp && resp.success) {
      infoList.value.data = resp.data
    }
  })
  getList()
}
function getList() {
  getProjectAll(filterInfo.value.query).then((res) => {
    if (res && res.success) {
      tableInfo.value.data = res.data
    }
  })
}
</script>
<style scoped lang="scss">
:deep(.table-scroll-hidden) > .el-table {
  overflow-y: hidden;
}
:deep(.el-dialog__body) {
  height: 355px;
  display: flex;
  flex-direction: column;
}
</style>
